package news.controller;

import news.service.AddTopicServiceImpl;
import news.service.IAddTopicService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * @author Administrator
 * 添加主题
 */
@WebServlet("/addTopic")
public class AddTopicController extends HttpServlet {
    private IAddTopicService iAddTopicService = new AddTopicServiceImpl();
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 设置响应内容类型
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("utf-8");
        //1.接受参数
        //2.存储数据
        String topicName = request.getParameter("topicName");

        iAddTopicService.addTopic(topicName);

        //3.返回成功响应

        request.getRequestDispatcher(request.getContextPath()+"/news/suc.jsp").forward(request,response);
    }

}